package com.payment.common.wxutils;
import com.payment.common.utils.UUIDGenerator;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.SortedMap;


/**
 * 相关配置参数
 *
 * @author hongyang.jiang
 */
@Component
@ConfigurationProperties(prefix = "wxpay")
public class WxConfigUtil {
    private String APP_ID;// 服务号的应用ID
    private String APP_SECRET;// 服务号的应用密钥
    private String TOKEN;// 服务号的配置token
    private String MCH_ID;// 商户号
    private String API_KEY;// API密钥
    private String SIGN_TYPE;// 签名加密方式
    private String CERT_PATH;//微信支付证书
    private String SERVICE_URL;
    private String NB_NOTIFY_URL;
    private String ME_NOTIFY_URL;
	private String notifyUrl;
	private String REDIRECT_URL;

	public String getNotifyUrl() {
		return notifyUrl;
	}

	public void setNotifyUrl(String notifyUrl) {
		this.notifyUrl = notifyUrl;
	}

	public String getREDIRECT_URL() {
		return REDIRECT_URL;
	}

	public void setREDIRECT_URL(String REDIRECT_URL) {
		this.REDIRECT_URL = REDIRECT_URL;
	}

	public String getAPP_ID() {
        return APP_ID;
    }

    public void setAPP_ID(String APP_ID) {
        this.APP_ID = APP_ID;
    }

    public String getAPP_SECRET() {
        return APP_SECRET;
    }

    public void setAPP_SECRET(String APP_SECRET) {
        this.APP_SECRET = APP_SECRET;
    }

    public String getTOKEN() {
        return TOKEN;
    }

    public void setTOKEN(String TOKEN) {
        this.TOKEN = TOKEN;
    }

    public String getMCH_ID() {
        return MCH_ID;
    }

    public void setMCH_ID(String MCH_ID) {
        this.MCH_ID = MCH_ID;
    }

    public String getAPI_KEY() {
        return API_KEY;
    }

    public void setAPI_KEY(String API_KEY) {
        this.API_KEY = API_KEY;
    }

    public String getSIGN_TYPE() {
        return SIGN_TYPE;
    }

    public void setSIGN_TYPE(String SIGN_TYPE) {
        this.SIGN_TYPE = SIGN_TYPE;
    }

    public String getCERT_PATH() {
        return CERT_PATH;
    }

    public void setCERT_PATH(String CERT_PATH) {
        this.CERT_PATH = CERT_PATH;
    }

    public String getSERVICE_URL() {
        return SERVICE_URL;
    }

    public void setSERVICE_URL(String SERVICE_URL) {
        this.SERVICE_URL = SERVICE_URL;
    }

    public String getNB_NOTIFY_URL() {
        return NB_NOTIFY_URL;
    }

    public void setNB_NOTIFY_URL(String NB_NOTIFY_URL) {
        this.NB_NOTIFY_URL = NB_NOTIFY_URL;
    }

    public String getME_NOTIFY_URL() {
        return ME_NOTIFY_URL;
    }

    public void setME_NOTIFY_URL(String ME_NOTIFY_URL) {
        this.ME_NOTIFY_URL = ME_NOTIFY_URL;
    }



	/*

	private static Configuration configs;
	public static synchronized void init(String filePath) {
		if (configs != null) {
			return;
		}
		try {
			configs = new PropertiesConfiguration(filePath);
		} catch (org.apache.commons.configuration.ConfigurationException e) {
			e.printStackTrace();
		}

		if (configs == null) {
			throw new IllegalStateException("can`t find file by path:"
					+ filePath);
		}
		APP_ID = configs.getString("APP_ID");
		APP_SECRET = configs.getString("APP_SECRET");
		TOKEN = configs.getString("TOKEN");
		MCH_ID = configs.getString("MCH_ID");
		API_KEY = configs.getString("API_KEY");
		SIGN_TYPE = configs.getString("SIGN_TYPE");
		CERT_PATH = configs.getString("CERT_PATH");
		SERVICE_URL = configs.getString("SERVICE_URL");
		NOTIFY_URL = configs.getString("NOTIFY_URL");
	}*/


    /**
     * 微信基础接口地址
     */
    // 获取token接口(GET)
    public final static String TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
    // oauth2授权接口(GET)
    public final static String OAUTH2_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
    // 刷新access_token接口（GET）
    public final static String REFRESH_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=APPID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN";
    // 菜单创建接口（POST）
    public final static String MENU_CREATE_URL = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
    // 菜单查询（GET）
    public final static String MENU_GET_URL = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN";
    // 菜单删除（GET）
    public final static String MENU_DELETE_URL = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN";
    /**
     * 微信支付接口地址
     */
    // 微信支付统一接口(POST)
    public final static String UNIFIED_ORDER_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder";
	// 微信付款码支付接口(POST)
	public final static String PAYCODE_URL = "https://api.mch.weixin.qq.com/pay/micropay";
    // 微信退款接口(POST)
    public final static String REFUND_URL = "https://api.mch.weixin.qq.com/secapi/pay/refund";
    // 订单查询接口(POST)
    public final static String CHECK_ORDER_URL = "https://api.mch.weixin.qq.com/pay/orderquery";
    // 关闭订单接口(POST)
    public final static String CLOSE_ORDER_URL = "https://api.mch.weixin.qq.com/pay/closeorder";
    // 退款查询接口(POST)
    public final static String CHECK_REFUND_URL = "https://api.mch.weixin.qq.com/pay/refundquery";
    // 对账单接口(POST)
    public final static String DOWNLOAD_BILL_URL = "https://api.mch.weixin.qq.com/pay/downloadbill";
    // 短链接转换接口(POST)
    public final static String SHORT_URL = "https://api.mch.weixin.qq.com/tools/shorturl";
    // 接口调用上报接口(POST)
    public final static String REPORT_URL = "https://api.mch.weixin.qq.com/payitil/report";


    /**
     * 基础参数
     *
     * @author hongyang.jiang
     */
    public static void commonParams(SortedMap<Object, Object> packageParams) {
        // 生成随机字符串
        String currTime = PayCommonUtil.getCurrTime();
        String strTime = currTime.substring(8, currTime.length());
        String strRandom = PayCommonUtil.buildRandom(4) + "";
        String nonce_str = strTime + strRandom;
        packageParams.put("nonce_str", nonce_str);// 随机字符串
    }

    /**
     * 基础参数
     *
     * @author hongyang.jiang
     */
    public static String getNoncestr() {
        // 生成随机字符串
        String currTime = PayCommonUtil.getCurrTime();
        String strTime = currTime.substring(8, currTime.length());
        String strRandom = PayCommonUtil.buildRandom(4) + "";
        String noncestr = strTime + strRandom;
        return UUIDGenerator.getUUID();
    }
}